package com.team.star.controller;


import com.team.star.entity.pojo.User;
import com.team.star.entity.vo.UserVO;
import com.team.star.service.UserService;
import com.team.star.utils.ResponseCode;
import com.team.star.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Tag(name = "用户管理")
public class UserController {
    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }


    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public Result<Void> login(@RequestBody UserVO userVO) {
        userService.login(userVO);
        return Result.success(ResponseCode.SUCCESS);
    }

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public Result<Void> register(@RequestBody UserVO userVO) {
        userService.register(userVO);
        return Result.success(ResponseCode.SUCCESS);
    }

    @GetMapping("/getUsers")
    @Operation(summary = "获取所有用户信息")
    public Result<List<User>> getUsers() {
        List<User> userList = userService.getUserList();
        return Result.success(ResponseCode.SUCCESS, userList);
    }
}
